var Site = {
	
	start: function(){
		
		if ($('kwick')) Site.parseKwicks();
		
		if ($('sidebar')){Site.appearText();}

		Site.sh('views');
		Site.sh('bike');
		Site.sh('subway');
		Site.sh('sky');

		Site.appearPhoto('views_p');
		
	},

	cr : 'views',
	
	sh : function(x){
		$(x).addEvent('click', function(){
			$(Site.cr+'_p').setStyle('display', 'none');
			Site.cr = x;
			$(x+'_p').setStyle('display', 'block');
			Site.appearPhoto(x+'_p');
		});
	},
	
	parseKwicks: function(){
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 185]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 105) obj[j] = {'width': [w, 105]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 125]};
			});
			fx.start(obj);
		});
	},
	
	appearPhoto: function(y){
		var timer = 0;
		var sideblocks = $$('#'+y+' img');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
				el.setStyle('margin-top', '-135px');	
				timer += 150;
				slidefxs[i] = new Fx.Style(el, 'margin-top', {
					duration: 400,
					transition: Fx.Transitions.backOut,
					wait: false,
					onComplete: Site.createOver.pass([el, i])
				});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#sidebar li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			if(i==0){	el.setStyle('margin-left', '0');	}
			else{	el.setStyle('margin-left', '-155px');	}
				timer += 150;
				slidefxs[i] = new Fx.Style(el, 'margin-left', {
					duration: 400,
					transition: Fx.Transitions.backOut,
					wait: false,
					onComplete: Site.createOver.pass([el, i])
				});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
	},
	
	createOver: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a') return;
		var overfxs = new Fx.Styles(first, {'duration': 200, 'wait': false});
		if (first.hasClass('big')){
			var tocolor = '333';
			var fromcolor = 'fff';
		} else {
			var tocolor = 'faec8f';
			var fromcolor = '595965';
		}
		el.mouseouted = true;
		el.addEvent('mouseenter', function(e){
			overfxs.start({
				'color': tocolor,
				'margin-left': 10
			});
		});
		el.addEvent('mouseleave', function(e){
			overfxs.start({
				'color': fromcolor,
				'margin-left': 0
			});
		});
	}
	
};


window.addEvent('load', Site.start);